package com.acraftsman.mr_camera.utils;

import android.content.Context;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class LocalScanUtils {

    public void showLed(String ipAddress, String level){
        final String finalIpAddress = ipAddress;
        final String finalLevel = level;
        new Thread() {
            public void run() {
                OkHttpClient client = new OkHttpClient();
                String ledUrl = "http://" +finalIpAddress + "/ptz_control.cgi?"+
                        "command=25&user=admin&pwd=12345678&param="+finalLevel;
                Request request = new Request.Builder().url(ledUrl).get().build();
                Response response = null;
                try {
                    response = client.newCall(request).execute();
                    String result = new String(response.body().bytes(), "utf-8");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }

    public void showKa(Context context) {
        MediaPlayer mShootSound = null;
        try {
            AudioManager meng = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            int volume = meng.getStreamVolume(AudioManager.STREAM_RING);
            if (volume != 0) {
                if (mShootSound == null) {
                    mShootSound = MediaPlayer.create(context, Uri.parse("file:///system/media/audio/ui/camera_click.ogg"));
                }
                if (mShootSound != null) {
                    mShootSound.start();
                }
            }
        } catch (Exception e) {
            System.out.println("showKa异常:" + e.getMessage());
        }
    }

}
